Lately, I've found myself repeatedly frustrated by the simple operation of copying and pasting text in HyperCard 2.0. The problem occurs when I go to paste the text. It seems that HyperCard (many other applications) now copy the style of the text as well as the text itself. This is great until you have to go to the different menus to set the font, size, and style. Here is the code for a short little FKEY that strips away the style from the scrap, leaving only text.
Handle NewClearSysHandle(long size){
asm{
move.l size,d0
NewHandle CLEAR+SYS
move.l a0,d0
}
}
void main(void){
long scrapsize, offset;
Handle h;
scrapsize=0L;
h=0L;
if (!(h=NewClearSysHandle(0)))
goto returnpoint;
scrapsize=GetScrap(h,'TEXT',&offset);
if (scrapsize>0){
SetHandleSize(h,scrapsize+(scrapsize &1)); /*make Handle even size*/
ZeroScrap();
PutScrap(scrapsize,'TEXT',*h);
SystemEdit(3); /* Tricky part */
}
returnpoint:
if (h)
DisposHandle(h);
}
See the call to SystemEdit(3)? Well it took me FOREVER to figure that one out. The system won't recognize that the scrap has changed until you do it. I hope I'm not the only programmer out there that's had problems with this one!
For Think C project…
Project type->Code Resource
Type: FKEY (all capitols)
ID: 7 (this is also the number key that invokes FKEY)
Attrs: 20 (purgable)
File Type: rsrc (ResEdit)
Creator: RSED (ResEdit)
Name: Strip Style FKEY
Tom Nielsen, Recommended Testing
Note that I included a full C Project, and MacPaint document showing the Project settings. MacTutor can use the source and this note anyway it sees fit (just so long as I can show the article to my mother and she would believe that I wrote it).